package megrez.bussiness.schedule.repository;

import java.text.MessageFormat;

import org.springframework.data.jpa.domain.Specification;

import lombok.experimental.UtilityClass;
import megrez.bussiness.schedule.entity.Job;

/**
 * 任务信息查询条件
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@UtilityClass
public class JobSpecification {
    public Specification<Job> beanNameLike(String beanName) {
        return (root, query, builder) -> builder.like(root.get("beanName"), contains(beanName));

    }

    public Specification<Job> remarkLike(String remark) {
        return (root, query, builder) -> builder.like(root.get("remark"), contains(remark));

    }

    public Specification<Job> enabledEqual(boolean enabled) {
        return (root, query, builder) -> builder.equal(root.get("enabled"), enabled);

    }

    private String contains(String expression) {
        return MessageFormat.format("%{0}%", expression);
    }
}
